
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/19/2012 12:16:18
-- Generated from EDMX file: C:\Projets\Youfood\Entities\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [YouFoodDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_RestaurantZone]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Zones] DROP CONSTRAINT [FK_RestaurantZone];
GO
IF OBJECT_ID(N'[dbo].[FK_ZoneTable]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tables] DROP CONSTRAINT [FK_ZoneTable];
GO
IF OBJECT_ID(N'[dbo].[FK_ServeurZone]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Zones] DROP CONSTRAINT [FK_ServeurZone];
GO
IF OBJECT_ID(N'[dbo].[FK_CuisinierPreparationPlat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PreparationPlats] DROP CONSTRAINT [FK_CuisinierPreparationPlat];
GO
IF OBJECT_ID(N'[dbo].[FK_FormulePlat_Formule]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FormulePlat] DROP CONSTRAINT [FK_FormulePlat_Formule];
GO
IF OBJECT_ID(N'[dbo].[FK_FormulePlat_Plat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FormulePlat] DROP CONSTRAINT [FK_FormulePlat_Plat];
GO
IF OBJECT_ID(N'[dbo].[FK_CommandePlat_Commande]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommandePlat] DROP CONSTRAINT [FK_CommandePlat_Commande];
GO
IF OBJECT_ID(N'[dbo].[FK_CommandePlat_Plat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommandePlat] DROP CONSTRAINT [FK_CommandePlat_Plat];
GO
IF OBJECT_ID(N'[dbo].[FK_CommandeFormule_Commande]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommandeFormule] DROP CONSTRAINT [FK_CommandeFormule_Commande];
GO
IF OBJECT_ID(N'[dbo].[FK_CommandeFormule_Formule]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommandeFormule] DROP CONSTRAINT [FK_CommandeFormule_Formule];
GO
IF OBJECT_ID(N'[dbo].[FK_CarteSpecialite]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Cartes] DROP CONSTRAINT [FK_CarteSpecialite];
GO
IF OBJECT_ID(N'[dbo].[FK_CarteFormule]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Formules] DROP CONSTRAINT [FK_CarteFormule];
GO
IF OBJECT_ID(N'[dbo].[FK_CartePlat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Plats] DROP CONSTRAINT [FK_CartePlat];
GO
IF OBJECT_ID(N'[dbo].[FK_ServeurCommande]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Commandes] DROP CONSTRAINT [FK_ServeurCommande];
GO
IF OBJECT_ID(N'[dbo].[FK_SpecialitePlat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Plats] DROP CONSTRAINT [FK_SpecialitePlat];
GO
IF OBJECT_ID(N'[dbo].[FK_TableCommande]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Commandes] DROP CONSTRAINT [FK_TableCommande];
GO
IF OBJECT_ID(N'[dbo].[FK_PreparationPlatCommande]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PreparationPlats] DROP CONSTRAINT [FK_PreparationPlatCommande];
GO
IF OBJECT_ID(N'[dbo].[FK_NotificationCommande]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notifications] DROP CONSTRAINT [FK_NotificationCommande];
GO
IF OBJECT_ID(N'[dbo].[FK_NotificationServeur]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notifications] DROP CONSTRAINT [FK_NotificationServeur];
GO
IF OBJECT_ID(N'[dbo].[FK_NotificationPreparationPlat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notifications] DROP CONSTRAINT [FK_NotificationPreparationPlat];
GO
IF OBJECT_ID(N'[dbo].[FK_PreparationPlatPlat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PreparationPlats] DROP CONSTRAINT [FK_PreparationPlatPlat];
GO
IF OBJECT_ID(N'[dbo].[FK_CuisinierRestaurant]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Utilisateurs_Cuisinier] DROP CONSTRAINT [FK_CuisinierRestaurant];
GO
IF OBJECT_ID(N'[dbo].[FK_DeviceTable]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Utilisateurs_Device] DROP CONSTRAINT [FK_DeviceTable];
GO
IF OBJECT_ID(N'[dbo].[FK_DeviceRestaurant]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Utilisateurs_Device] DROP CONSTRAINT [FK_DeviceRestaurant];
GO
IF OBJECT_ID(N'[dbo].[FK_ServeurRestaurant]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Utilisateurs_Serveur] DROP CONSTRAINT [FK_ServeurRestaurant];
GO
IF OBJECT_ID(N'[dbo].[FK_ManagerRestaurant]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Restaurants] DROP CONSTRAINT [FK_ManagerRestaurant];
GO
IF OBJECT_ID(N'[dbo].[FK_Serveur_inherits_Utilisateur]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Utilisateurs_Serveur] DROP CONSTRAINT [FK_Serveur_inherits_Utilisateur];
GO
IF OBJECT_ID(N'[dbo].[FK_Cuisinier_inherits_Utilisateur]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Utilisateurs_Cuisinier] DROP CONSTRAINT [FK_Cuisinier_inherits_Utilisateur];
GO
IF OBJECT_ID(N'[dbo].[FK_Device_inherits_Utilisateur]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Utilisateurs_Device] DROP CONSTRAINT [FK_Device_inherits_Utilisateur];
GO
IF OBJECT_ID(N'[dbo].[FK_Manager_inherits_Utilisateur]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Utilisateurs_Manager] DROP CONSTRAINT [FK_Manager_inherits_Utilisateur];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Cartes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Cartes];
GO
IF OBJECT_ID(N'[dbo].[Commandes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Commandes];
GO
IF OBJECT_ID(N'[dbo].[Formules]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Formules];
GO
IF OBJECT_ID(N'[dbo].[Notifications]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Notifications];
GO
IF OBJECT_ID(N'[dbo].[Plats]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Plats];
GO
IF OBJECT_ID(N'[dbo].[PreparationPlats]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PreparationPlats];
GO
IF OBJECT_ID(N'[dbo].[Restaurants]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Restaurants];
GO
IF OBJECT_ID(N'[dbo].[Specialites]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Specialites];
GO
IF OBJECT_ID(N'[dbo].[Tables]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tables];
GO
IF OBJECT_ID(N'[dbo].[Utilisateurs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Utilisateurs];
GO
IF OBJECT_ID(N'[dbo].[Zones]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Zones];
GO
IF OBJECT_ID(N'[dbo].[Utilisateurs_Serveur]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Utilisateurs_Serveur];
GO
IF OBJECT_ID(N'[dbo].[Utilisateurs_Cuisinier]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Utilisateurs_Cuisinier];
GO
IF OBJECT_ID(N'[dbo].[Utilisateurs_Device]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Utilisateurs_Device];
GO
IF OBJECT_ID(N'[dbo].[Utilisateurs_Manager]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Utilisateurs_Manager];
GO
IF OBJECT_ID(N'[dbo].[FormulePlat]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FormulePlat];
GO
IF OBJECT_ID(N'[dbo].[CommandePlat]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommandePlat];
GO
IF OBJECT_ID(N'[dbo].[CommandeFormule]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommandeFormule];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Cartes'
CREATE TABLE [dbo].[Cartes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nom] nvarchar(max)  NULL,
    [DateCreation] datetime  NULL,
    [SpecialiteId] int  NOT NULL
);
GO

-- Creating table 'Commandes'
CREATE TABLE [dbo].[Commandes] (
    [Id] int  NOT NULL,
    [Date] datetime  NULL,
    [EstRegle] bit  NOT NULL,
    [EtatCommande] nvarchar(max)  NULL,
    [Prix] smallint  NOT NULL,
    [Serveur_Id] int  NULL,
    [Table_Id] int  NOT NULL
);
GO

-- Creating table 'Formules'
CREATE TABLE [dbo].[Formules] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nom] nvarchar(max)  NULL,
    [Description] nvarchar(max)  NULL,
    [Prix] float  NOT NULL,
    [CarteId] int  NOT NULL
);
GO

-- Creating table 'Notifications'
CREATE TABLE [dbo].[Notifications] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NULL,
    [Date] datetime  NULL,
    [Fait] bit  NOT NULL,
    [CommandeId] int  NOT NULL,
    [PreparationPlatId] int  NULL,
    [PreparationPlatId1] int  NOT NULL,
    [Serveur_Id] int  NOT NULL
);
GO

-- Creating table 'Plats'
CREATE TABLE [dbo].[Plats] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NULL,
    [Nom] nvarchar(max)  NULL,
    [Description] nvarchar(max)  NULL,
    [Prix] float  NOT NULL,
    [CarteId] int  NOT NULL,
    [SpecialiteId] int  NOT NULL
);
GO

-- Creating table 'PreparationPlats'
CREATE TABLE [dbo].[PreparationPlats] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DateSoumission] datetime  NULL,
    [Etat] nvarchar(max)  NULL,
    [CommandeId] int  NOT NULL,
    [Cuisinier_Id] int  NULL,
    [Plat_Id] int  NOT NULL
);
GO

-- Creating table 'Restaurants'
CREATE TABLE [dbo].[Restaurants] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nom] nvarchar(max)  NULL,
    [Description] nvarchar(max)  NULL,
    [Adresse] nvarchar(max)  NULL,
    [Capacite] int  NOT NULL,
    [Telephone] int  NOT NULL,
    [Email] nvarchar(max)  NULL,
    [Manager_Id] int  NULL
);
GO

-- Creating table 'Specialites'
CREATE TABLE [dbo].[Specialites] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nom] nvarchar(max)  NULL
);
GO

-- Creating table 'Tables'
CREATE TABLE [dbo].[Tables] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Numero] int  NOT NULL,
    [Capacite] int  NOT NULL,
    [estOccupe] bit  NOT NULL,
    [ZoneId] int  NOT NULL
);
GO

-- Creating table 'Utilisateurs'
CREATE TABLE [dbo].[Utilisateurs] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Email] nvarchar(max)  NULL,
    [Password] nvarchar(max)  NULL,
    [DateCreation] datetime  NULL,
    [DateDernierLogin] datetime  NULL
);
GO

-- Creating table 'Zones'
CREATE TABLE [dbo].[Zones] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Numero] int  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [RestaurantId] int  NOT NULL,
    [Serveur_Id] int  NULL
);
GO

-- Creating table 'Utilisateurs_Serveur'
CREATE TABLE [dbo].[Utilisateurs_Serveur] (
    [ZoneAttribue_Id] int  NULL,
    [Nom] nvarchar(50)  NULL,
    [Prenom] nvarchar(50)  NULL,
    [RestaurantId] int  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Utilisateurs_Cuisinier'
CREATE TABLE [dbo].[Utilisateurs_Cuisinier] (
    [Nom] nvarchar(50)  NULL,
    [Prenom] nvarchar(50)  NULL,
    [RestaurantId] int  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Utilisateurs_Device'
CREATE TABLE [dbo].[Utilisateurs_Device] (
    [TableId] int  NULL,
    [RestaurantId] int  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Utilisateurs_Manager'
CREATE TABLE [dbo].[Utilisateurs_Manager] (
    [Telephone] int  NOT NULL,
    [Nom] nvarchar(50)  NULL,
    [Prenom] nvarchar(50)  NULL,
    [RestaurantId] int  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'FormulePlat'
CREATE TABLE [dbo].[FormulePlat] (
    [Formule_Id] int  NOT NULL,
    [Plat_Id] int  NOT NULL
);
GO

-- Creating table 'CommandePlat'
CREATE TABLE [dbo].[CommandePlat] (
    [Commande_Id] int  NOT NULL,
    [Plat_Id] int  NOT NULL
);
GO

-- Creating table 'CommandeFormule'
CREATE TABLE [dbo].[CommandeFormule] (
    [Commande_Id] int  NOT NULL,
    [Formule_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Cartes'
ALTER TABLE [dbo].[Cartes]
ADD CONSTRAINT [PK_Cartes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Commandes'
ALTER TABLE [dbo].[Commandes]
ADD CONSTRAINT [PK_Commandes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Formules'
ALTER TABLE [dbo].[Formules]
ADD CONSTRAINT [PK_Formules]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Notifications'
ALTER TABLE [dbo].[Notifications]
ADD CONSTRAINT [PK_Notifications]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Plats'
ALTER TABLE [dbo].[Plats]
ADD CONSTRAINT [PK_Plats]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PreparationPlats'
ALTER TABLE [dbo].[PreparationPlats]
ADD CONSTRAINT [PK_PreparationPlats]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Restaurants'
ALTER TABLE [dbo].[Restaurants]
ADD CONSTRAINT [PK_Restaurants]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Specialites'
ALTER TABLE [dbo].[Specialites]
ADD CONSTRAINT [PK_Specialites]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Tables'
ALTER TABLE [dbo].[Tables]
ADD CONSTRAINT [PK_Tables]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Utilisateurs'
ALTER TABLE [dbo].[Utilisateurs]
ADD CONSTRAINT [PK_Utilisateurs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Zones'
ALTER TABLE [dbo].[Zones]
ADD CONSTRAINT [PK_Zones]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Utilisateurs_Serveur'
ALTER TABLE [dbo].[Utilisateurs_Serveur]
ADD CONSTRAINT [PK_Utilisateurs_Serveur]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Utilisateurs_Cuisinier'
ALTER TABLE [dbo].[Utilisateurs_Cuisinier]
ADD CONSTRAINT [PK_Utilisateurs_Cuisinier]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Utilisateurs_Device'
ALTER TABLE [dbo].[Utilisateurs_Device]
ADD CONSTRAINT [PK_Utilisateurs_Device]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Utilisateurs_Manager'
ALTER TABLE [dbo].[Utilisateurs_Manager]
ADD CONSTRAINT [PK_Utilisateurs_Manager]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Formule_Id], [Plat_Id] in table 'FormulePlat'
ALTER TABLE [dbo].[FormulePlat]
ADD CONSTRAINT [PK_FormulePlat]
    PRIMARY KEY NONCLUSTERED ([Formule_Id], [Plat_Id] ASC);
GO

-- Creating primary key on [Commande_Id], [Plat_Id] in table 'CommandePlat'
ALTER TABLE [dbo].[CommandePlat]
ADD CONSTRAINT [PK_CommandePlat]
    PRIMARY KEY NONCLUSTERED ([Commande_Id], [Plat_Id] ASC);
GO

-- Creating primary key on [Commande_Id], [Formule_Id] in table 'CommandeFormule'
ALTER TABLE [dbo].[CommandeFormule]
ADD CONSTRAINT [PK_CommandeFormule]
    PRIMARY KEY NONCLUSTERED ([Commande_Id], [Formule_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [RestaurantId] in table 'Zones'
ALTER TABLE [dbo].[Zones]
ADD CONSTRAINT [FK_RestaurantZone]
    FOREIGN KEY ([RestaurantId])
    REFERENCES [dbo].[Restaurants]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RestaurantZone'
CREATE INDEX [IX_FK_RestaurantZone]
ON [dbo].[Zones]
    ([RestaurantId]);
GO

-- Creating foreign key on [ZoneId] in table 'Tables'
ALTER TABLE [dbo].[Tables]
ADD CONSTRAINT [FK_ZoneTable]
    FOREIGN KEY ([ZoneId])
    REFERENCES [dbo].[Zones]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ZoneTable'
CREATE INDEX [IX_FK_ZoneTable]
ON [dbo].[Tables]
    ([ZoneId]);
GO

-- Creating foreign key on [Serveur_Id] in table 'Zones'
ALTER TABLE [dbo].[Zones]
ADD CONSTRAINT [FK_ServeurZone]
    FOREIGN KEY ([Serveur_Id])
    REFERENCES [dbo].[Utilisateurs_Serveur]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ServeurZone'
CREATE INDEX [IX_FK_ServeurZone]
ON [dbo].[Zones]
    ([Serveur_Id]);
GO

-- Creating foreign key on [Cuisinier_Id] in table 'PreparationPlats'
ALTER TABLE [dbo].[PreparationPlats]
ADD CONSTRAINT [FK_CuisinierPreparationPlat]
    FOREIGN KEY ([Cuisinier_Id])
    REFERENCES [dbo].[Utilisateurs_Cuisinier]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CuisinierPreparationPlat'
CREATE INDEX [IX_FK_CuisinierPreparationPlat]
ON [dbo].[PreparationPlats]
    ([Cuisinier_Id]);
GO

-- Creating foreign key on [Formule_Id] in table 'FormulePlat'
ALTER TABLE [dbo].[FormulePlat]
ADD CONSTRAINT [FK_FormulePlat_Formule]
    FOREIGN KEY ([Formule_Id])
    REFERENCES [dbo].[Formules]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Plat_Id] in table 'FormulePlat'
ALTER TABLE [dbo].[FormulePlat]
ADD CONSTRAINT [FK_FormulePlat_Plat]
    FOREIGN KEY ([Plat_Id])
    REFERENCES [dbo].[Plats]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FormulePlat_Plat'
CREATE INDEX [IX_FK_FormulePlat_Plat]
ON [dbo].[FormulePlat]
    ([Plat_Id]);
GO

-- Creating foreign key on [Commande_Id] in table 'CommandePlat'
ALTER TABLE [dbo].[CommandePlat]
ADD CONSTRAINT [FK_CommandePlat_Commande]
    FOREIGN KEY ([Commande_Id])
    REFERENCES [dbo].[Commandes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Plat_Id] in table 'CommandePlat'
ALTER TABLE [dbo].[CommandePlat]
ADD CONSTRAINT [FK_CommandePlat_Plat]
    FOREIGN KEY ([Plat_Id])
    REFERENCES [dbo].[Plats]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CommandePlat_Plat'
CREATE INDEX [IX_FK_CommandePlat_Plat]
ON [dbo].[CommandePlat]
    ([Plat_Id]);
GO

-- Creating foreign key on [Commande_Id] in table 'CommandeFormule'
ALTER TABLE [dbo].[CommandeFormule]
ADD CONSTRAINT [FK_CommandeFormule_Commande]
    FOREIGN KEY ([Commande_Id])
    REFERENCES [dbo].[Commandes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Formule_Id] in table 'CommandeFormule'
ALTER TABLE [dbo].[CommandeFormule]
ADD CONSTRAINT [FK_CommandeFormule_Formule]
    FOREIGN KEY ([Formule_Id])
    REFERENCES [dbo].[Formules]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CommandeFormule_Formule'
CREATE INDEX [IX_FK_CommandeFormule_Formule]
ON [dbo].[CommandeFormule]
    ([Formule_Id]);
GO

-- Creating foreign key on [SpecialiteId] in table 'Cartes'
ALTER TABLE [dbo].[Cartes]
ADD CONSTRAINT [FK_CarteSpecialite]
    FOREIGN KEY ([SpecialiteId])
    REFERENCES [dbo].[Specialites]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CarteSpecialite'
CREATE INDEX [IX_FK_CarteSpecialite]
ON [dbo].[Cartes]
    ([SpecialiteId]);
GO

-- Creating foreign key on [CarteId] in table 'Formules'
ALTER TABLE [dbo].[Formules]
ADD CONSTRAINT [FK_CarteFormule]
    FOREIGN KEY ([CarteId])
    REFERENCES [dbo].[Cartes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CarteFormule'
CREATE INDEX [IX_FK_CarteFormule]
ON [dbo].[Formules]
    ([CarteId]);
GO

-- Creating foreign key on [CarteId] in table 'Plats'
ALTER TABLE [dbo].[Plats]
ADD CONSTRAINT [FK_CartePlat]
    FOREIGN KEY ([CarteId])
    REFERENCES [dbo].[Cartes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CartePlat'
CREATE INDEX [IX_FK_CartePlat]
ON [dbo].[Plats]
    ([CarteId]);
GO

-- Creating foreign key on [Serveur_Id] in table 'Commandes'
ALTER TABLE [dbo].[Commandes]
ADD CONSTRAINT [FK_ServeurCommande]
    FOREIGN KEY ([Serveur_Id])
    REFERENCES [dbo].[Utilisateurs_Serveur]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ServeurCommande'
CREATE INDEX [IX_FK_ServeurCommande]
ON [dbo].[Commandes]
    ([Serveur_Id]);
GO

-- Creating foreign key on [SpecialiteId] in table 'Plats'
ALTER TABLE [dbo].[Plats]
ADD CONSTRAINT [FK_SpecialitePlat]
    FOREIGN KEY ([SpecialiteId])
    REFERENCES [dbo].[Specialites]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SpecialitePlat'
CREATE INDEX [IX_FK_SpecialitePlat]
ON [dbo].[Plats]
    ([SpecialiteId]);
GO

-- Creating foreign key on [Table_Id] in table 'Commandes'
ALTER TABLE [dbo].[Commandes]
ADD CONSTRAINT [FK_TableCommande]
    FOREIGN KEY ([Table_Id])
    REFERENCES [dbo].[Tables]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TableCommande'
CREATE INDEX [IX_FK_TableCommande]
ON [dbo].[Commandes]
    ([Table_Id]);
GO

-- Creating foreign key on [CommandeId] in table 'PreparationPlats'
ALTER TABLE [dbo].[PreparationPlats]
ADD CONSTRAINT [FK_PreparationPlatCommande]
    FOREIGN KEY ([CommandeId])
    REFERENCES [dbo].[Commandes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PreparationPlatCommande'
CREATE INDEX [IX_FK_PreparationPlatCommande]
ON [dbo].[PreparationPlats]
    ([CommandeId]);
GO

-- Creating foreign key on [CommandeId] in table 'Notifications'
ALTER TABLE [dbo].[Notifications]
ADD CONSTRAINT [FK_NotificationCommande]
    FOREIGN KEY ([CommandeId])
    REFERENCES [dbo].[Commandes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NotificationCommande'
CREATE INDEX [IX_FK_NotificationCommande]
ON [dbo].[Notifications]
    ([CommandeId]);
GO

-- Creating foreign key on [Serveur_Id] in table 'Notifications'
ALTER TABLE [dbo].[Notifications]
ADD CONSTRAINT [FK_NotificationServeur]
    FOREIGN KEY ([Serveur_Id])
    REFERENCES [dbo].[Utilisateurs_Serveur]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NotificationServeur'
CREATE INDEX [IX_FK_NotificationServeur]
ON [dbo].[Notifications]
    ([Serveur_Id]);
GO

-- Creating foreign key on [PreparationPlatId1] in table 'Notifications'
ALTER TABLE [dbo].[Notifications]
ADD CONSTRAINT [FK_NotificationPreparationPlat]
    FOREIGN KEY ([PreparationPlatId1])
    REFERENCES [dbo].[PreparationPlats]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NotificationPreparationPlat'
CREATE INDEX [IX_FK_NotificationPreparationPlat]
ON [dbo].[Notifications]
    ([PreparationPlatId1]);
GO

-- Creating foreign key on [Plat_Id] in table 'PreparationPlats'
ALTER TABLE [dbo].[PreparationPlats]
ADD CONSTRAINT [FK_PreparationPlatPlat]
    FOREIGN KEY ([Plat_Id])
    REFERENCES [dbo].[Plats]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PreparationPlatPlat'
CREATE INDEX [IX_FK_PreparationPlatPlat]
ON [dbo].[PreparationPlats]
    ([Plat_Id]);
GO

-- Creating foreign key on [RestaurantId] in table 'Utilisateurs_Cuisinier'
ALTER TABLE [dbo].[Utilisateurs_Cuisinier]
ADD CONSTRAINT [FK_CuisinierRestaurant]
    FOREIGN KEY ([RestaurantId])
    REFERENCES [dbo].[Restaurants]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CuisinierRestaurant'
CREATE INDEX [IX_FK_CuisinierRestaurant]
ON [dbo].[Utilisateurs_Cuisinier]
    ([RestaurantId]);
GO

-- Creating foreign key on [TableId] in table 'Utilisateurs_Device'
ALTER TABLE [dbo].[Utilisateurs_Device]
ADD CONSTRAINT [FK_DeviceTable]
    FOREIGN KEY ([TableId])
    REFERENCES [dbo].[Tables]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DeviceTable'
CREATE INDEX [IX_FK_DeviceTable]
ON [dbo].[Utilisateurs_Device]
    ([TableId]);
GO

-- Creating foreign key on [RestaurantId] in table 'Utilisateurs_Device'
ALTER TABLE [dbo].[Utilisateurs_Device]
ADD CONSTRAINT [FK_DeviceRestaurant]
    FOREIGN KEY ([RestaurantId])
    REFERENCES [dbo].[Restaurants]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DeviceRestaurant'
CREATE INDEX [IX_FK_DeviceRestaurant]
ON [dbo].[Utilisateurs_Device]
    ([RestaurantId]);
GO

-- Creating foreign key on [RestaurantId] in table 'Utilisateurs_Serveur'
ALTER TABLE [dbo].[Utilisateurs_Serveur]
ADD CONSTRAINT [FK_ServeurRestaurant]
    FOREIGN KEY ([RestaurantId])
    REFERENCES [dbo].[Restaurants]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ServeurRestaurant'
CREATE INDEX [IX_FK_ServeurRestaurant]
ON [dbo].[Utilisateurs_Serveur]
    ([RestaurantId]);
GO

-- Creating foreign key on [Manager_Id] in table 'Restaurants'
ALTER TABLE [dbo].[Restaurants]
ADD CONSTRAINT [FK_ManagerRestaurant]
    FOREIGN KEY ([Manager_Id])
    REFERENCES [dbo].[Utilisateurs_Manager]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ManagerRestaurant'
CREATE INDEX [IX_FK_ManagerRestaurant]
ON [dbo].[Restaurants]
    ([Manager_Id]);
GO

-- Creating foreign key on [Id] in table 'Utilisateurs_Serveur'
ALTER TABLE [dbo].[Utilisateurs_Serveur]
ADD CONSTRAINT [FK_Serveur_inherits_Utilisateur]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Utilisateurs]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Utilisateurs_Cuisinier'
ALTER TABLE [dbo].[Utilisateurs_Cuisinier]
ADD CONSTRAINT [FK_Cuisinier_inherits_Utilisateur]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Utilisateurs]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Utilisateurs_Device'
ALTER TABLE [dbo].[Utilisateurs_Device]
ADD CONSTRAINT [FK_Device_inherits_Utilisateur]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Utilisateurs]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Utilisateurs_Manager'
ALTER TABLE [dbo].[Utilisateurs_Manager]
ADD CONSTRAINT [FK_Manager_inherits_Utilisateur]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Utilisateurs]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------